/*
write by       : wuweiwei (邬畏畏)
blogs          : www.blogs.com/wsoft
WUI            : www.flybirdsoft.com/WUI

function:

*/


/*
options = {
	width : n ,
	height : n ,
	tipHTML : "" ,
	left : n ,
	top : n
	} ,
	HTML : ""
}
*/

var phonePop = function(p,options){
	this.options = options;
	this.parentName = p;
	this.$parent = $(p);
	this.createMask();
	this.createLayer();
	this.initEvent();
};

phonePop.prototype.createLayer = function(){
	var body = document.getElementsByTagName("body")[0];
	var iLayer = document.createElement("div");
	iLayer.className = "phonePop-phoneButton";
	iLayer.innerHTML = this.options.tipHTML || "&nbsp;";
	this.$parent[0].appendChild(iLayer);

	var iBox = document.createElement("div");
	iBox.id = "phonePop_phoneBox";
	iBox.className = "phonePop-phoneBox";
	iBox.style.zIndex = 5011;
	iBox.style.position = "fixed";
	iBox.style.left = this.options.left || "50%";
	iBox.style.top = this.options.top || "50%";

	if(this.options.width.toString().indexOf("%")>0)
	{
		iBox.style.width = this.options.width;
		iBox.style.marginLeft = "-" + parseInt(this.options.width.replace("%",""))/2 + "%";
	}
	else
	{
		iBox.style.width = this.options.width + "px";
		iBox.style.marginLeft = "-" + this.options.width/2 + "px";
	}

	if(this.options.height.toString().indexOf("%")>0)
	{
		iBox.style.height = this.options.height;
		iBox.style.marginTop = "-" + parseInt(this.options.height.replace("%",""))/2 + "%";
	}
	else
	{
		iBox.style.height = this.options.height + "px";
		iBox.style.marginTop = "-" + this.options.height/2 + "px";
	}
	
	iBox.style.display = "none";
	body.appendChild(iBox);

	if(typeof(this.options.HTML)=="string")/*外界参数*/
	{
		iBox.innerHTML = this.options.HTML || '需要传入HTML参数，即：<br>new phonePop("p",{HTML=""})';
	}
	else if(typeof(this.options.HTML)=="object")
	{
		iBox.innerHTML = this.options.HTML.innerHTML || this.options.HTML[0].innerHTML;
		if(this.options.HTML.innerHTML != undefined)
		{
			this.options.HTML.innerHTML = "";
		}
		else
		{
			this.options.HTML[0].innerHTML = "";
		}
	}
	else if(typeof(this.options.HTML)=="undefined")
	{
		iBox.innerHTML = '需要传入HTML参数，<br>即：<br>new phonePop("p",{HTML=""})';
	}
}


phonePop.prototype.createMask = function(color){

	var mask = document.createElement("div");
	mask.id="phonePop_Mask";
	mask.className = "phonePop-Mask";
	mask.style.position = "fixed";
	mask.style.height = "100%";
	mask.style.width = "100%";
	mask.style.backgroundColor = "#555";
	mask.style.opacity = 0.3;
	mask.style.zIndex = 5010;
	mask.style.top = "0";
	mask.style.left = "0";
	mask.style.display = "none";
	var body = document.getElementsByTagName("body")[0];
	body.appendChild(mask);
}

phonePop.prototype.initEvent = function(){

	$(this.parentName + " .phonePop-phoneButton").bind("click",function(){
		$(".phonePop-phoneBox").show();
		$("#phonePop_Mask").show();
	});

}/*end function initEvent*/

phonePop.prototype.show = function(){
	$(".phonePop-phoneBox").show();
	$("#phonePop_Mask").show();
};

phonePop.prototype.hide = function(){
	$(".phonePop-phoneBox").hide();
	$("#phonePop_Mask").hide();
};





